Repository navigation
Conversation
… gap) Closes the follow-up deferred from the cap-rework review: the model-LOAD gate admits on an ESTIMATE (estimatedMemoryGb = on-disk weight bytes × 1.2), while the runtime KV budget uses MEASURED live MLX usage. If the estimate under-counts real residency, a model could load yet have its requests rejected by the KV gate — a "loaded but unserveable" model the coordinator keeps routing to. After a model is resident, both load paths now measure the true live KV headroom under the 90% cap and reject if it's below the minimum serveable KV: - BatchScheduler gains `measuredLiveKVHeadroomBytes` (liveKVHeadroomBytes from real MLX active+cache, with NO 1024-token floor so it reports a true zero) and `hasServeableKVHeadroom()` (>= UnifiedMemoryCap.minimumLoadKVBytes, 1 GiB). - ProviderLoop.ensureModelLoaded and StandaloneServer's lazy-load, right after loadModel returns and BEFORE registering the slot, unload + MLX.Memory .clearCache() + throw a clear "insufficient KV headroom … — unloaded" error (ProviderLoop records it for `doctor`; both mirror evictUntilAvailable so the coordinator reroutes). The check runs inside the `isLoadingAny` critical section, so the MLX measurement reflects this load with no concurrent race. This makes the cap invariant hold on MEASURED residency end-to-end, not just the estimate. Test: postLoadGuardRejectsWhenMeasuredHeadroomBelowMinimum pins the guard's boundary (an over-estimate-residency model → headroom < min → reject; a model with real room → admit). 59 tests green across UnifiedMemoryCap + BatchSchedulerBudget + StandaloneServer suites.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ethenotethan
left a comment
There was a problem hiding this comment.
Automated Code Review — Layr-Labs/d-inference#
Verdict: REQUEST_CHANGES
Security — ✅ No issues found
Performance — 4 finding(s) (1 blocking)
- 🟡 [MEDIUM]
coordinator/registry/scheduler.go:863-882— Complex memory calculation in hot path with multiple floating point operations- Suggestion: Pre-calculate constants like providerHardMemoryCapGB and providerEstimatedModelLoadGB outside the admission check, or cache results for repeated calls with same parameters
- 🔵 [INFO]
coordinator/api/consumer.go:1011-1017— implicitMaxTokensBound called twice with same parameters in handleChatCompletions- Suggestion: Store the result of implicitMaxTokensBound(rec.MaxOutputLength) in a variable to avoid duplicate computation
- 🔵 [INFO]
coordinator/api/consumer.go:4106-4108— implicitMaxTokensBound called twice with same parameters in handleGenericInference- Suggestion: Store the result of implicitMaxTokensBound(rec.MaxOutputLength) in a variable to avoid duplicate computation
- 🔵 [INFO]
provider-swift/Sources/ProviderCore/Inference/BatchScheduler.swift:1466-1490— SamplingParams struct created and modified multiple times in makeSamplingParams- Suggestion: Initialize SamplingParams with all known values at once instead of creating then modifying with conditional assignments
Type_diligence — 4 finding(s) (2 blocking)
- 🟡 [MEDIUM]
coordinator/api/consumer.go:1008— map[string]any used for core request parsing without type safety- Suggestion: Define a typed struct for request parsing instead of map[string]any to catch field type mismatches at compile time
- 🟡 [MEDIUM]
coordinator/api/consumer.go:1188— map[string]any used for request modification without type safety- Suggestion: Define a typed struct for request parsing instead of map[string]any to catch field type mismatches at compile time
- 🔵 [INFO]
coordinator/api/consumer.go:1048— explicitMaxTokens function operates on map[string]any without type assertions- Suggestion: Add type assertions with ok checks when accessing map values, e.g., if val, ok := parsed["max_tokens"].(int); ok { ... }
- 🔵 [INFO]
coordinator/api/consumer_test.go:1047-1051— Test uses map[string]any without type safety for test data- Suggestion: Use a typed struct for test request data instead of map[string]any to ensure type safety in tests
Additive_complexity — 5 finding(s) (2 blocking)
- 🔵 [INFO]
coordinator/api/consumer.go:1009-1016— implicitMaxTokensBound function adds unnecessary indirection for simple min operation- Suggestion: Inline the logic at call sites:
min(defaultMaxOutputTokens, modelMaxOutputLength)when modelMaxOutputLength > 0
- Suggestion: Inline the logic at call sites:
- 🔵 [INFO]
coordinator/registry/scheduler.go:135-142— Five new memory-related constants when existing modelMemoryHeadroomFactor served similar purpose- Suggestion: Consider consolidating these constants or documenting why the existing factor pattern wasn't sufficient
- 🟡 [MEDIUM]
coordinator/registry/scheduler.go:165-184— providerHardMemoryCapGB duplicates memory calculation pattern from existing modelFitsHardware- Suggestion: Extract shared memory calculation logic into a common helper function to avoid divergent implementations
- 🔵 [INFO]
provider-swift/Sources/ProviderCore/Inference/BatchScheduler.swift:1466-1490— makeSamplingParams static method extracts common parameter construction but only used in two places- Suggestion: Consider inlining this helper since it's only used twice and the abstraction doesn't hide significant complexity
- 🔴 [CRITICAL]
coordinator/registry/scheduler.go:807-882— freeMemoryAdmits function grew from simple free memory check to complex multi-path logic with provider-specific constants- Suggestion: Split into separate functions for cold-load vs warm-model admission logic, each with clear responsibilities and test coverage
13 finding(s) total, 5 blocking. Verdict: REQUEST_CHANGES.
🤖 Automated review by Centaur · DAR-186
…x/gemma-oom-repetition # Conflicts: # provider-swift/Sources/ProviderCore/Inference/BatchScheduler+Telemetry.swift # provider-swift/Sources/ProviderCore/ProviderLoop.swift # provider-swift/Sources/ProviderCore/Server/StandaloneServer.swift # provider-swift/Tests/ProviderCoreTests/UnifiedMemoryCapTests.swift
ethenotethan
left a comment
There was a problem hiding this comment.
Automated Code Review — Layr-Labs/d-inference#
Verdict: REQUEST_CHANGES
Security — ✅ No issues found
Performance — 3 finding(s) (3 blocking)
- 🟡 [MEDIUM]
coordinator/registry/scheduler.go:813-881— freeMemoryAdmits performs redundant calculations of providerEstimatedModelLoadGB and providerHardMemoryCapGB on every call- Suggestion: Cache these calculations in the routingSnapshot struct or pre-compute them when the snapshot is created to avoid repeated floating-point arithmetic on hot scheduling paths
- 🟡 [MEDIUM]
coordinator/api/consumer.go:1008-1016— implicitMaxTokensBound performs the same comparison and calculation repeatedly for identical inputs- Suggestion: Add memoization or cache the result since modelMaxOutputLength values are likely to repeat frequently across requests for the same model
- 🟡 [MEDIUM]
provider-swift/Sources/ProviderCore/Inference/BatchScheduler.swift:1465-1490— makeSamplingParams creates new SamplingParams struct on every call with repeated validation logic- Suggestion: Consider object pooling for SamplingParams or pre-validate common parameter combinations to reduce allocation overhead in high-throughput scenarios
Type_diligence — 4 finding(s)
- 🔵 [INFO]
coordinator/api/consumer.go:1015— explicitMaxTokens uses map[string]any for JSON parsing- Suggestion: Consider defining a typed struct for request parsing with proper field tags, or use a more specific interface for the expected JSON structure
- 🔵 [INFO]
coordinator/api/consumer.go:1188— ensureMaxTokensBound uses map[string]any for request modification- Suggestion: Consider defining a typed struct for request parsing and modification with proper field tags
- 🔵 [INFO]
coordinator/api/consumer.go:1542— handleChatCompletions uses map[string]any for JSON parsing- Suggestion: Consider defining a typed struct for chat completion requests with proper field tags
- 🔵 [INFO]
coordinator/api/consumer.go:4108— handleGenericInference uses map[string]any for JSON parsing- Suggestion: Consider defining a typed struct for generic inference requests with proper field tags
Additive_complexity — 6 finding(s) (2 blocking)
- 🔵 [INFO]
coordinator/api/consumer.go:1011-1016— implicitMaxTokensBound function adds unnecessary indirection for simple conditional logic- Suggestion: Inline this 6-line function at its call sites or use a simple ternary expression
- 🔵 [INFO]
coordinator/registry/scheduler.go:136-142— Five new memory-related constants add configuration complexity without clear necessity- Suggestion: Consider if these constants could be derived from existing values or if fewer knobs would suffice
- 🔵 [INFO]
coordinator/registry/scheduler.go:165-177— providerHardMemoryCapGB function wraps simple arithmetic in unnecessary abstraction- Suggestion: Inline this calculation or use a simple math.Min call at the usage site
- 🔵 [INFO]
coordinator/registry/scheduler.go:179-184— providerEstimatedModelLoadGB function is trivial wrapper around multiplication- Suggestion: Replace with inline calculation: modelSizeGB * providerModelMemoryOverheadFactor
- 🟡 [MEDIUM]
provider-swift/Sources/ProviderCore/Inference/BatchScheduler.swift:1466-1489— makeSamplingParams static method extracts common parameter construction but adds cognitive overhead- Suggestion: Consider if the duplication removal justifies the added indirection, or inline at call sites
- 🟡 [MEDIUM]
coordinator/registry/scheduler.go:810-882— freeMemoryAdmits function has grown complex with multiple memory calculation paths and edge cases- Suggestion: Split into separate functions for cold-load vs warm-model admission logic to improve readability
13 finding(s) total, 5 blocking. Verdict: REQUEST_CHANGES.
🤖 Automated review by Centaur · DAR-186
|
Superseded — split into focused PRs. This branch bundled three unrelated concerns; here's where each went:
No code from this branch is lost — the keep-worthy half is #379, the rest is already on master. |
The rebased SDK #364 keeps main's operation-count Gemma4DecodeCommandBuffers (mlx-swift-lm #376, adopted here by #1712) instead of its earlier scoped 100-operation/512 M-element limit, so this pin adds only the dense GeGLU product. Say so in the inference and hardware notes and the changelog fragment, and note that the endpoint screen measured both changes together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layr-Labs/mlx-swift-lm#364 was rebased onto main 67110e7b (dev's pin), so this moves the gitlink from dev's 67110e7b to its new head. The rebased SDK change is the dense GeGLU product (plus its tests, benchmark record and DocC reference fixes); its decode command-buffer limits resolved to main's #376 policy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layr-Labs/mlx-swift-lm#365 (compiled Gemma feed-forward graphs) was rebased onto the rebased #364, so this moves the gitlink to its new head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layr-Labs/mlx-swift-lm#364 was rebased onto main 67110e7b (dev's pin), so this moves the gitlink from dev's 67110e7b to its new head. The rebased SDK change is the dense GeGLU product (plus its tests, benchmark record and DocC reference fixes); its decode command-buffer limits resolved to main's #376 policy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layr-Labs/mlx-swift-lm#365 (compiled Gemma feed-forward graphs) was rebased onto the rebased #364, so this moves the gitlink to its new head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The library pull request branch now holds a merge of library main 7f196e02c2, so the pin moves from 6d2c82a0e4 to that merge. The merge adds library #395 (nullable tool arguments), #302 (the Qwen3.5 MTP prefill projects only the last prompt position), #364 (the Gemma 4 dispatch change), #365 (reuse of compiled Gemma 4 feed-forward graphs) and #366 (greedy batches skip unused sampler metadata). dev does not have them yet. No provider source changes. The pin stays provisional until the library pull request merges. Co-Authored-By: Claude <noreply@anthropic.com>
libs/mlx-swift-lm moves from fd48d47f to 093563be, the merge commit of mlx-swift-lm #367 on main. It holds every 0.10.12 SDK PR, each merged with a merge commit: #372, #301, #395 (nullable tool arguments), #302, #364, #365, #366 and #367. libs/mlx-swift and libs/mlx are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libs/mlx-swift-lm moves from 04940f55 to 093563be, the merge commit of mlx-swift-lm #367 on main. It holds every 0.10.12 SDK PR, each merged with a merge commit: #372, #301, #395 (nullable tool arguments), #302, #364, #365, #366 and #367. libs/mlx-swift and libs/mlx are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libs/mlx-swift-lm moves from 1aace467 to 093563be, the merge commit of mlx-swift-lm #367 on main. It holds every 0.10.12 SDK PR, each merged with a merge commit: #372, #301, #395 (nullable tool arguments), #302, #364, #365, #366 and #367. libs/mlx-swift and libs/mlx are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libs/mlx-swift-lm moves from f6b9ac22 to 093563be, the merge commit of mlx-swift-lm #367 on main. It holds every 0.10.12 SDK PR, each merged with a merge commit: #372, #301, #395 (nullable tool arguments), #302, #364, #365, #366 and #367. libs/mlx-swift and libs/mlx are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libs/mlx-swift-lm moves from 51da1368 to 093563be, the merge commit of mlx-swift-lm #367 on main. It holds every 0.10.12 SDK PR, each merged with a merge commit: #372, #301, #395 (nullable tool arguments), #302, #364, #365, #366 and #367. libs/mlx-swift and libs/mlx are unchanged. changelog.d/qwen35-mtp-prefill-last-row.md: mlx-swift-lm #302 (Qwen 3.5 MTP prompts project only their last position) rides this pin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Why
Gemma 4 26B QAT was repeating under continuous batching because the batched KV cache forced explicit all-true masks for n == 1 decode, while the regular KVCache path uses no mask. That matches the upstream MLX issue shape and the screenshots. The memory-envelope changes remain useful defense-in-depth for the crash/OOM family.
Tests
Notes
This PR is stacked on feat/unified-memory-cap. The submodule code review is in Layr-Labs/mlx-swift-lm#40.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.